# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/8/24
# @File : TPM（step2）E. Segments with Small Set（CF）.py

def TPM():
    l = 0
    num = 0#不同数字的个数
    res = 0
    for r in range(n):
        d[rate[r]] += 1
        if(d[rate[r]]==1):
            num += 1
        while(num > k):
            d[rate[l]] -= 1
            if(d[rate[l]]==0):
                num -= 1
            l += 1
        res += (r-l+1)
    return res

"""
同样的C题的框架：res += (r-l+1)
if the segment [L,R] is good, then any segment nested in it is also good (in this case, 
you can apply the code from the first problem);

用字典来维护区间内每个数字出现的次数

"""
if __name__ == "__main__":
    n,k = map(int,input().split())
    rate = [int(i) for i in input().split()]
    d = dict()
    for i in rate:#初始化字典
        d[i] = 0
    ans = TPM()
    print(ans)
